package com.xinyu.maker.generator.file;

import com.xinyu.maker.generator.file.DynamicFileGenerator;
import com.xinyu.maker.generator.file.StaticFileGenerator;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 核心生成器
 *
 * @author: Wuxinyu
 * @date: 2024/5/12-05-12-22:11
 * @description: com.xinyu.generator
 * @version: 1.0
 */
public class FileGenerator {

    /**
     * 生成静态文件和动态文件
     *
     * @param model
     * @throws TemplateException
     * @throws IOException
     */
    public static void doGenerate(Object model) throws TemplateException, IOException {
        // 当前idea打开的窗口
        String projectPath = System.getProperty("user.dir");
        // 输入路径 ACM的示例模板 在 code-generator-demo-projects 目录下
        String inputPath = new File(projectPath + File.separator + "code-generator-demo-projects/acm-template").getAbsolutePath();
        // 输出路径
        String outputPath = projectPath;
        // 生成静态文件
        StaticFileGenerator.copyFilesByHuTool(inputPath, outputPath);
        // 生成动态文件，会覆盖部分已生成的静态文件
        String inputDynamicFilePath = projectPath + File.separator + "code-generator-maker" + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        String outputDynamicFilePath = projectPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";
        DynamicFileGenerator.doGenerate(inputDynamicFilePath, outputDynamicFilePath, model);
    }
}
